
#include "HSCMRPressure.h"
#include "..\System\F2806x_Device.h"
#include <math.h>

bool HSCMRPressure::Init()
{
	// init I2C Driver
	m_SAR = 0x0028; // BMP085 I2C address
	InitI2C();

	return true;
}

void HSCMRPressure::Process()
{
	// Read P
	Uint32 data;
	Read4Bytes(&data);

	m_Pressure = (data >> 16) & (0x3FFF); // remove 2 MSB bits (status)
	m_Temperature = (data & 0x0FFFF) >> 5;

	float Pressure = ((float)m_Pressure-1638.0f)*1 / (14746-1638); // p.s.i.
	// convert to Pa
	Pressure = Pressure * 6894.757280343134f; // to [Pa]
	m_P = Pressure;

	float Temperature = ((float)m_Temperature*200.0f)/2047.0f - 50.0f;
	m_T = Temperature;
}

float HSCMRPressure::GetPressure()
{
	return m_P;
}

float HSCMRPressure::GetTemperature()
{
	return m_T;
}
